<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>当前任务</title>
	<link rel="stylesheet" href="Css/bootstrap.min.css">
	<link rel="stylesheet" href="Css/login.css">
</head>
<body>
	<div class="container">
	<div class="row clearfix" id="header">
		<div class="col-md-11 column">
			<h3 class="text-center">
				正在进行的任务>>>>>>
			</h3>
		</div>
		<div class="col-md-1 column">
			<a href="/scucource/login.html">重新登录</a>
		</div>
	</div>
	<div class="row clearfix">
		<div class="col-md-2 column">
		</div>
		<div class="col-md-6 column">
			<table class="table table-default">
				<thead>
					<tr>
						<th>
							任务编号
						</th>
						<th>
							课程号
						</th>
						<th>
							课序号
						</th>
						<th>
							课程名
						</th>
						<th>
							状态
						</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id = "tbody">
					
				</tbody>
			</table>
			<button type="button" class="btn btn-default" id="btn-add">新增</button>
		</div>
		<div class="col-md-4 column">
		</div>
	</div>
</div>

<script src="Js/jquery.min.js"></script>
	<script src="Js/bootstrap.min.js"></script>

	<script>
	function statusIdToString(status_id){
		var msg ="";
		switch(status_id){
		case 0:
			msg = "初始化";
			break;
		case 1:
			msg = "运行中";
			break;
		case 2:
			msg = "已完成";
			break;
		case 3:
			msg = "出错了";
			break;
		case 4:
			msg = "取消";
			break;
		case 5:
			msg = "休眠中";
			break;
		default:
				msg = "未知的状态";
		}
		return msg;
	}
	$(function(){
		$.getJSON('/scucource/scucorse/core/tasks',function(data){
			if(data.status == 0){
				data = data.content;
				l	=	data.length;
				i	=	0;
				//$('#tbody').html()
				var tbody = "";
				while(i<l){
					status = statusIdToString(data[i].status);
					var trs = "";
		            trs += "<tr><td>" + data[i].id + "</td> <td>" + data[i].coursenumber + "</td> <td>" +
		            data[i].sycnumber + "</td> <td>" + data[i].coursename + "</td> <td>" + status + "</td></tr>";
					tbody += trs;
		            i++;
				}
				
			}else{
				alert('任务列表获取失败！请尝试重新登录，或添加任务。');
			}
			$('#tbody').append(tbody);
		});
	});
	
	$(document).ready(function() {
		$('#btn-add').click(function() {
			url = "/scucource/addTask.html"
			window.location.href = url;
		});
	}); 
	</script>
</body>
</html>